<script lang="ts" setup name="ServiceDialog">
import { FormInstance } from 'element-plus'
import { cloneDeep } from 'lodash-es'
import { Dialog } from '~/src/api/interface'
import { StoreManagement } from '~/src/api/interface/storeManagement'

const dialogProps = ref<Dialog<Partial<StoreManagement.Service>>>({
  title: '新增',
  data: {},
  visible: false,
})
const rules = reactive({
  name: [{ required: true, message: '请填写服务商名称' }],
})
// 接收父组件传过来的参数
const acceptParams = (params: Dialog<Partial<StoreManagement.Service>>) => {
  dialogProps.value = cloneDeep(params)
  dialogProps.value.visible = true
}

// 提交数据（新增/编辑）
const ruleFormRef = ref<FormInstance>()
const handleSubmit = async () => {
  await ruleFormRef.value!.validate()
  await useHandleDialog(
    dialogProps.value.api as (params: any) => Promise<any>,
    dialogProps.value.data,
    dialogProps.value.getTableList as () => void
  )
  dialogProps.value.visible = false
}

defineExpose({
  acceptParams,
})
</script>

<template>
  <vab-dialog v-model:modelValue="dialogProps.visible" destroy-on-close :title="dialogProps.title + '部门'" :width="600">
    <el-form ref="ruleFormRef" label-suffix=" :" label-width="120px" :model="dialogProps.data" :rules="rules">
      <el-form-item label="编码" prop="number">
        <el-input v-model="dialogProps.data!.number" disabled />
      </el-form-item>
      <el-form-item label="帐号余额" prop="balance">
        <el-input v-model="dialogProps.data!.balance" disabled />
      </el-form-item>
      <el-form-item label="名称" prop="name">
        <el-input v-model="dialogProps.data!.name" clearable />
      </el-form-item>
      <el-form-item label="联系人" prop="linkMan">
        <el-input v-model="dialogProps.data!.linkMan" clearable />
      </el-form-item>
      <el-form-item label="联系电话" prop="mobile">
        <el-input v-model="dialogProps.data!.mobile" clearable />
      </el-form-item>
      <!-- <el-form-item label="分服务器" prop="isCreateFacCode">
        <el-select class="w100" v-model="dialogProps.row!.isCreateFacCode">
          <el-option label="创建" :value="true" />
          <el-option label="不创建" :value="false" />
        </el-select>
      </el-form-item> -->
    </el-form>
    <template #footer>
      <el-button @click="dialogProps.visible = false">取消</el-button>
      <el-button type="primary" @click="handleSubmit">确定</el-button>
    </template>
  </vab-dialog>
</template>

<style lang="scss" scoped></style>
